package com.jiyiren.bms.aty;

import android.content.res.Configuration;
import android.content.res.Resources;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Window;

import com.jiyiren.bms.App;

import java.util.Locale;

public class BaseCompatActivity extends AppCompatActivity {
    protected App mapp;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        mapp=App.getAppInstance();
//        switchLanguage("en");
        switchLanguage(mapp.getLanguage());
    }

    protected void switchLanguage(String language)
    {
//        if(mapp.getIshasLanguage()&&mapp.getLanguage().equals(language)){
//            return;
//        }
        // 设置应用语言类型
        Resources resources = getResources();
        Configuration config = resources.getConfiguration();
        DisplayMetrics dm = resources.getDisplayMetrics();
        if (language.equals("en"))
        {
            config.locale = Locale.ENGLISH;
        }
        else
        {
            // 简体中文
            config.locale = Locale.SIMPLIFIED_CHINESE;
        }
        resources.updateConfiguration(config, dm);

        // 保存设置语言的类型
        mapp.setLanguage(language);
    }
}
